var resizeTimeoutId;
$(window).load(function () {
    resize();
});

$(function () {
    // Various browsers will call window.resize event twice.  
    // The following prevents that and makes sure it only runs once.
    // It also makes sure that the resize code is not run until resizing is completed.
    $(window).resize(function (e) {
        window.clearTimeout(resizeTimeoutId);
        resizeTimeoutId = window.setTimeout('resize();', 10);
    });

    $('.events .main-content .button, .events .cta a').not('a.view-demo').click(function (e) {
        e.preventDefault();
        $('.registration-form').fadeIn('fast');
        $('.close-iframe').css('display','block');
    });
    
    // close the event registration when escape key is pressed.
    $(document).keyup(function(e) {
		if (e.keyCode == 27) { 
			$('.registration-form').fadeOut('fast');
			$('.close-iframe').css('display','none'); 
		}   // esc
	})
	$('.close-iframe').click(function() {
		$('.registration-form').fadeOut('fast');
		$('.close-iframe').css('display','none');
	});

    _gaq.push(function() {
      var pageTracker = _gat._getTrackerByName();
      var iframe = $('.registration-form');
      iframe.attr('src', pageTracker._getLinkerUrl(iframe.attr('src')));
    });
})

function resize() {
    var windowHeight = $(this).height();
    var footerHeight = 114 - parseInt($('footer').css('padding-bottom'));
    var bodyHeight = $('body').height();
    var maxFooterWidth = 1171;
    var footerWidth = $('footer').width();
    if (windowHeight > bodyHeight) {
        $('footer').height(footerHeight + windowHeight - bodyHeight);
    }
    else {
        $('footer').height(114);
    }
    
    if (footerWidth > maxFooterWidth) {
        var padding = (footerWidth - maxFooterWidth) / 2;
        $('footer .social, footer .logo').removeAttr('style');
        var newLeftPad = parseInt($('footer .social').css('left')) + padding;
        var newRightPad = parseInt($('footer .logo').css('right')) + padding;
        $('footer .social').css('left', newLeftPad);
        $('footer .logo').css('right', newRightPad);
    }
}
